---
title: Performance optimization
---

GraphQL Helix allows you to provide your own `parse`, `validate`, `execute` and `subscribe` functions in place of the default ones provided by `graphql-js`. This makes it possible to utilize libraries like [GraphQL JIT](https://github.com/zalando-incubator/graphql-jit) by providing an appropriate `validate` function:

```ts
const result = await processRequest({
  // ...
  execute: (schema, documentAst, rootValue, contextValue, variableValues, operationName) => {
    const compiledQuery = compileQuery(schema, documentAst, operationName);

    if (isCompiledQuery(compiledQuery)) {
      return compiledQuery.query(rootValue, contextValue, variableValues || {});
    }

    return compiledQuery;
  },
});
```

> ⚠️ GraphQL JIT is an experimental library that is still lacking some features required by the GraphQL specification. You probably should not use it in production unless you know what you're getting yourself into.

The ability to provide custom implementations of `parse` and `validate` means we can also optimize the performance of those individual steps by introducing caching. This allows us to bypass these steps for queries we've processed before.

For example, we can create a simple in-memory cache

```ts
import lru from "tiny-lru";

const cache = lru(1000, 3600000);
```

and then use it to cache our parsed queries so we can skip that step for subsequent requests:

```ts
import { parse } from "graphql";

const result = await processRequest({
  operationName,
  query,
  variables,
  request,
  schema,
  parse: (source, options) => {
    if (!cache.get(query)) {
      cache.set(query, parse(source, options));
    }

    return cache.get(query);
  },
});
```

We can take a similar approach with `validate` and even cache the result of `compileQuery` if we're using GraphQL JIT. See [this example](examples/graphql-jit) for a more complete implementation.
